package com.ruoyi.web.controller.businessSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.system.domain.vo.TableSettingsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TableSettings;
import com.ruoyi.system.service.ITableSettingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 桌台设置 Controller
 *
 * @author ruoyi
 * @date 2025-05-12
 */

@Api(tags="桌台设置")
@RestController
@RequestMapping("/system/tableSettings")
public class TableSettingsController extends BaseController
{
    @Autowired
    private ITableSettingsService tableSettingsService;

    /**
     * 查询桌台设置列表
     */
    @ApiOperation("查询桌台设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(TableSettings tableSettings)
    {
        startPage();
        List<TableSettings> list = tableSettingsService.selectTableSettingsList(tableSettings);
        return getDataTable(list);
    }

    /**
     * 导出桌台设置列表
     */
    @ApiOperation("导出桌台设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:export')")
    @Log(title = "桌台设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TableSettings tableSettings)
    {
        List<TableSettings> list = tableSettingsService.selectTableSettingsList(tableSettings);
        ExcelUtil<TableSettings> util = new ExcelUtil<TableSettings>(TableSettings.class);
        util.exportExcel(response, list, "桌台设置数据");
    }

    /**
     * 通过id获取桌台设置信息
     */
    @ApiOperation("通过id获取桌台设置信息")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tableSettingsService.selectTableSettingsById(id));
    }

    /**
     * 新增桌台设置
     */
    @ApiOperation("新增桌台设置")
    @PreAuthorize("@ss.hasPermi('system:settings:add')")
    @Log(title = "桌台设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TableSettings tableSettings)
    {
        return toAjax(tableSettingsService.insertTableSettings(tableSettings));
    }

    /**
     * 修改桌台设置
     */
    @ApiOperation("修改桌台设置")
    @PreAuthorize("@ss.hasPermi('system:settings:edit')")
    @Log(title = "桌台设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TableSettings tableSettings)
    {
        return toAjax(tableSettingsService.updateTableSettings(tableSettings));
    }

    /**
     * 通过id批量删除桌台设置信息
     */
    @ApiOperation("通过id批量删除桌台设置信息")
    @PreAuthorize("@ss.hasPermi('system:settings:remove')")
    @Log(title = "桌台设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tableSettingsService.deleteTableSettingsByIds(ids));
    }

    /**
     * 根据门店ID查询桌台设置详情
     */
    @ApiOperation("根据门店ID查询桌台设置详情")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping("/detail/{storeId}")
    public AjaxResult getTableSettingsDetail(@PathVariable("storeId") Long storeId) {
        TableSettingsVO tableSettingsVO = tableSettingsService.selectByStoreId(storeId);
        return success(tableSettingsVO);
    }

}
